import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Cache } from "../../../cache/Cache";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { LookupPlayerData } from "../LookupPlayerData";
import { EEntityAttribute } from "../../../../../Message/Public/EEntityAttribute";
import { ItemConfig } from "../../../resource/ItemConfig";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { ItemData } from "../../../resource/info/ItemData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ShopRule } from "../../../rules/ShopRule";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { ShopConfig } from "../../../resource/ShopConfig";
import { EffectManager } from "../../../manager/EffectManager";
type int = number;
//class MedalPanel
    
    export  class MedalPanel /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public get mode(): string
        {
            return this._mode;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            return;
        }

        /* internal  */init(): void
        {
            this._medalBg = new Object /* flash.display.Bitmap */();
            addChild(this._medalBg);
            LoaderHelp.addResCallBack(ResFileConst.medal, this.onResLoaded);
            this.buttonMode = true;
            this.useHandCursor = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            return;
        }

        public updateMedal(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.medal, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            var loc2=null;
            var loc4=null;
            this._medalBg.bitmapData = null;
            var loc1=Cache.instance.role.medalCode;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode != GModuleEvent.Mode_Other) 
                {
                    return;
                }
                else 
                {
                    loc1 = LookupPlayerData.lookupData.medalMap[EEntityAttribute._EAttributeMedal] as int;
                }
            }
            else 
            {
                loc1 = Cache.instance.role.medalCode;
            }
            if (loc1 == 0) 
            {
                if ((loc4 = ItemConfig.instance.getItemByTypeAndLevel(ECategory._ECategoryProp, EProp._EPropMedal, -1, 0)) && loc4.item) 
                {
                    loc2 = new ItemData(loc4.item.code);
                }
            }
            else 
            {
                loc2 = new ItemData(loc1);
            }
            var loc3=1;
            if (loc2 && loc2.itemInfo) 
            {
                loc3 = loc2.itemInfo.item.itemLevel;
            }
            if (loc3 <= 0) 
            {
                loc3 = 1;
            }
            this._medalBg.bitmapData = GlobalClass.getBitmapData("medal_" + loc3);
            if (loc1 != 0) 
            {
                this._medalBg.filters = [];
            }
            else 
            {
                this._medalBg.filters = [FilterConst.colorFilter];
            }
            if (loc2) 
            {
                this.toolTipData = loc2.getToolTipData();
            }
            return;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._toolTipData = arg1;
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.mode == GModuleEvent.Mode_Self) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopOpenMerit, ShopRule.getShopId(ENpcEffect._ENpcEffectMeritExchange)));
            }
            return;
        }

        public guideMedal(): void
        {
            var loc5=null;
            var loc1=Cache.instance.role.money.merit;
            var loc2=ShopRule.getShopId(ENpcEffect._ENpcEffectMeritExchange);
            var loc3=ShopConfig.instance.getShopByName(loc2);
            var loc4=loc3.items;
            var loc6=0;
            while (loc6 < loc4.length) 
            {
                loc5 = loc4[loc6];
                if (loc1 >= loc5.tshopSell.price && Cache.instance.role.medalCode < loc5.tshopSell.itemCode) 
                {
                    EffectManager.glowFilterReg(this, [FilterConst.uiBtnFilter], 0.8, 10, 5, 10);
                    return;
                }
                ++loc6;
            }
            return;
        }

        /* internal */ /* var */_medalBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_mode: string="自己";

        protected /* var */_toolTipData;
    }
